package First;

import javax.sound.midi.Soundbank;

public class TalkPackage extends ServicePackage implements CallService, SendService {
    int talkTime;  // 通话时长(分钟)
    int smsCount;// 短信条数
    public TalkPackage(double price) {
        this.price=price;
        this.talkTime=500;
        this.smsCount=30;
    }
    @Override
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    @Override
    public void showInfo() {
        System.out.println("话痨套餐:通话时长为"+talkTime+"分钟/月,短信条数为:"
                +smsCount+"条/月,月资费"+price +"元");
    }
    @Override
    public int call(int minCount, MobileCard card) {
        int extra=0;
        if (minCount<=talkTime) {
            talkTime-=minCount;
        } else {
            extra=minCount-talkTime;
            talkTime = 0;
            // 额外通话按0.2元/分钟计费
            card.setConsumAmount(card.getConsumAmount()+extra*0.2);
        }
        card.setRealTalkTime(card.getRealTalkTime()+minCount);
        return extra;
    }
    @Override
    public int send(int count,MobileCard card) {
        int extra=0;
        if (count<=smsCount) {
            smsCount-=count;
        } else {
            extra =count-smsCount;
            smsCount = 0;
            //额外短信按0.1元/条计费
            card.setConsumAmount(card.getConsumAmount()+extra*0.1);
        }
        card.setRealSMSCount(card.getRealSMSCount()+count);
        return extra;
    }
    public int getTalkTime() {
        return talkTime;
    }
    public int getSmsCount() {
        return smsCount;
    }
}
